import { defineConfig, ConfigEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
//@ts-ignore
import eslint from 'vite-plugin-eslint'
import path from 'path'
// 引入svg用到的插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// 配置mock接口
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig(({ command }: ConfigEnv) => {
  return {
    plugins: [
      vue(),
      // {
      //   ...eslint({
      //     failOnWarning: false,
      //     failOnError: false,
      //   }),
      //   apply: 'serve',
      //   enforce: 'post',
      // },
      // SVG图标插件配置
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]',
      }),
      // mock接口 https://github.com/vbenjs/vite-plugin-mock/blob/main/README.zh_CN.md
      viteMockServe({
        mockPath: 'mock',
        enable: true,
      }),
    ],
    resolve: {
      alias: {
        '@': path.resolve('./src'), // 相对路径配置别名
      },
    },
    //scss配置全局样式变量
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    server: {
      proxy: {
        '/api': {
          target: 'http://localhost:5000',
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  }
})
